using Game.XH;
using UnityEngine;

namespace Game.Component.Character
{
	public class CharacterComponent
	{
		public Transform transform;

		public Transform spriteTrans;

		public SpriteRenderer spriteRenderer;

		public CharacterComponent(Transform trans)
		{
			transform = trans;
			spriteTrans = trans.Find("Sprite");
			if (spriteTrans != null)
			{
				spriteRenderer = spriteTrans.GetComponent<SpriteRenderer>();
			}
		}

		protected void ChangeSpriteColor(Transform trans, Color32 color)
		{
			ChangeSpriteColor(trans.Find("Sprite").GetComponent<SpriteRenderer>(), color);
		}

		protected void ChangeSpriteColor(SpriteRenderer spriteRenderer, Color32 color)
		{
			if (spriteRenderer != null)
			{
				spriteRenderer.color = color;
			}
		}

		protected void ChangeSprite(Transform copy)
		{
			if (spriteRenderer != null)
			{
				ChangeSprite(spriteRenderer, copy);
			}
		}

		protected void ChangeSprite(Transform trans, Transform copy)
		{
			ChangeSprite(trans.Find("Sprite").GetComponent<SpriteRenderer>(), copy);
		}

		protected void ChangeSprite(Transform trans, SpriteRenderer copySpriteRenderer)
		{
			ChangeSprite(trans.Find("Sprite").GetComponent<SpriteRenderer>(), copySpriteRenderer);
		}

		protected void ChangeSprite(SpriteRenderer spriteRenderer, Transform copy)
		{
			if (copy != null)
			{
				SpriteRenderer component = copy.GetComponent<SpriteRenderer>();
				ChangeSprite(spriteRenderer, component);
			}
			else
			{
				spriteRenderer.sprite = null;
			}
		}

		protected void ChangeSprite(SpriteRenderer spriteRenderer, SpriteRenderer copySpriteRenderer)
		{
			if (copySpriteRenderer != null)
			{
				spriteRenderer.sprite = copySpriteRenderer.sprite;
				spriteRenderer.transform.SetLocalXY(copySpriteRenderer.transform.localPosition);
			}
			else
			{
				spriteRenderer.sprite = null;
			}
		}
	}
}
